#ifndef _WAITQUEUE_H
#define _WAITQUEUE_H

#include <ds/list.h>

typedef struct waitqueue {
    lnode_t queue;
    bool (*deadlock_checker)(void* data); // returns true if is deadlocked and be solved, false otherwise
} waitq_t;

static inline void waitq_init(waitq_t* queue, bool (*deadlock_checker)(void* data)) {
    queue->deadlock_checker = deadlock_checker;
    list_head_init(&queue->queue);
}

void prepare_to_wait(waitq_t* queue);

void try_wait();

void wait_on(waitq_t* queue);

void wake_one(waitq_t* queue);

void wake_all(waitq_t* queue);

#endif /* _WAITQUEUE_H */